home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / CSFinalHack Module / Custom Def Utils.c next >
Encoding:
C/C++ Source or Header  |  2001-06-23  |  1.3 KB  |  50 lines

  1. /*----------------------------------------------------------------------------
  2.  
  3.     Custom Def Utils.c
  4.  
  5.     This module contains functions for dealing with xDEF stubs.
  6.     Code was adapted from a post in c.s.m.p '95 about custom MDEFs.
  7.     
  8.     Copyright © 1998, Ammon Skidmore.
  9.     
  10. ----------------------------------------------------------------------------*/
  11.  
  12. #include    <MixedMode.h>
  13. #include    "Custom Def Utils.h"
  14.  
  15.  
  16. Handle    GetUniversalFunctionHandle(ProcPtr functionAddress,ProcInfoType
  17. pInfo)
  18. {
  19.     Handle                pHNullProc = NULL;
  20.     ISAType                isa;
  21.     UniversalProcPtr     axDEFUPP;
  22.     
  23.     isa = GetCurrentISA();
  24.     
  25.     if (isa == kPowerPCISA)
  26.     {
  27.        pHNullProc = NewHandle(sizeof(RoutineDescriptor));
  28.        axDEFUPP = NewRoutineDescriptor(functionAddress,pInfo,isa);
  29.        BlockMove(axDEFUPP, *pHNullProc, sizeof(RoutineDescriptor));
  30.        DisposeRoutineDescriptor(axDEFUPP);
  31.     }
  32.     else
  33.     {
  34. #pragma unused (pInfo)
  35.         
  36.        pHNullProc = NewHandle(sizeof(JmpInstructionTemplate));
  37.        PatchJmpInstruction(*pHNullProc, (void*)functionAddress);
  38.     }
  39.     return(pHNullProc);
  40. }
  41.  
  42.  
  43. void PatchJmpInstruction(void* patchAddress, void* jumpAddress)
  44. {
  45.    JmpInstructionTemplate* aJmpInstructionPtr;
  46.    
  47.    aJmpInstructionPtr = (JmpInstructionTemplate *) patchAddress;
  48.    aJmpInstructionPtr->Jmp = 0x4EF9;
  49.    aJmpInstructionPtr->Routine = jumpAddress;
  50. }